package br.edu.utfpr.backupTools.view.action.configuracao;

import br.edu.utfpr.backupTools.app.Aplication;
import br.edu.utfpr.backupTools.controller.ControladorConfiguracaoImpl;
import br.edu.utfpr.backupTools.controller.interfaces.ControladorConfiguracao;
import br.edu.utfpr.backupTools.controller.validator.ConfiguracaoValidator;
import br.edu.utfpr.backupTools.model.dao.DaoConfiguracaoImpl;
import br.edu.utfpr.backupTools.model.dao.interfaces.DaoConfiguracao;
import br.edu.utfpr.backupTools.model.pojo.Configuracao;
import br.edu.utfpr.backupTools.util.enums.Acao;
import br.edu.utfpr.backupTools.view.action.AbstractCommand;
import br.edu.utfpr.comum.RetornoValidacao;
import br.edu.utfpr.backupTools.view.action.strategy.Control;

public class SalvarConfiguracoes extends AbstractCommand<Configuracao> {

    DaoConfiguracao dao = new DaoConfiguracaoImpl();
    ControladorConfiguracao controlador = new ControladorConfiguracaoImpl(dao, new ConfiguracaoValidator());

    @Override
    public RetornoValidacao execute(Configuracao bean) {
        boolean log = Control.getInstance().listCommand().get(Acao.LISTAR_CONFIGURACAO).execute().isEmpty();
        RetornoValidacao rv = controlador.save(bean);
        if (rv.isOk()) {
            Aplication.agendaBackups(bean,log);
        }
        return rv;
    }

}
